package com.ruoyi.sl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sl.domain.SlOfcLeave;
import com.ruoyi.sl.service.ISlOfcLeaveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 请假信息Controller
 * 
 * @author admin
 * @date 2024-06-14
 */
@RestController
@RequestMapping("/sl/leave")
public class SlOfcLeaveController extends BaseController
{
    @Autowired
    private ISlOfcLeaveService slOfcLeaveService;

    /**
     * 查询请假信息列表
     */
    @PreAuthorize("@ss.hasPermi('sl:monthofc:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlOfcLeave slOfcLeave)
    {
        startPage();
        List<SlOfcLeave> list = slOfcLeaveService.selectSlOfcLeaveList(slOfcLeave);
        return getDataTable(list);
    }

    /**
     * 导出请假信息列表
     */
    @PreAuthorize("@ss.hasPermi('sl:monthofc:export')")
    @Log(title = "请假信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlOfcLeave slOfcLeave)
    {
        List<SlOfcLeave> list = slOfcLeaveService.selectSlOfcLeaveList(slOfcLeave);
        ExcelUtil<SlOfcLeave> util = new ExcelUtil<SlOfcLeave>(SlOfcLeave.class);
        util.exportExcel(response, list, "请假信息数据");
    }

    /**
     * 获取请假信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('sl:monthofc:query')")
    @GetMapping(value = "/{leaveMpayId}")
    public AjaxResult getInfo(@PathVariable("leaveMpayId") Long leaveMpayId)
    {
        return success(slOfcLeaveService.selectSlOfcLeaveByLeaveMpayId(leaveMpayId));
    }

    /**
     * 新增请假信息
     */
    @PreAuthorize("@ss.hasPermi('sl:monthofc:add')")
    @Log(title = "请假信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlOfcLeave slOfcLeave)
    {
        return toAjax(slOfcLeaveService.insertSlOfcLeave(slOfcLeave));
    }

    /**
     * 修改请假信息
     */
    @PreAuthorize("@ss.hasPermi('sl:monthofc:edit')")
    @Log(title = "请假信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlOfcLeave slOfcLeave)
    {
        return toAjax(slOfcLeaveService.updateSlOfcLeave(slOfcLeave));
    }

    /**
     * 删除请假信息
     */
    @PreAuthorize("@ss.hasPermi('sl:monthofc:remove')")
    @Log(title = "请假信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{leaveMpayIds}")
    public AjaxResult remove(@PathVariable Long[] leaveMpayIds)
    {
        return toAjax(slOfcLeaveService.deleteSlOfcLeaveByLeaveMpayIds(leaveMpayIds));
    }
}
